bitkeeper revision 1.1062.3.7 (40f2c856i0jGNAZ3xZZ9fZILH7YDhw)
authormjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Mon, 12 Jul 2004 17:20:22 +0000 (17:20 +0000)
committermjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Mon, 12 Jul 2004 17:20:22 +0000 (17:20 +0000)
Fix sxpr conversion for forms.
Fix args for restore.

tools/python/xen/xend/Args.py
tools/python/xen/xend/XendClient.py
tools/python/xen/xend/server/SrvDomain.py

index 31bc067d072298428d8e618c377c51cfed418c7b..f70000a9d58c28fd3eaf0a32a73cab9893cc30e2 100644 (file)
@@ -1,4 +1,6 @@
 import types
+import StringIO
+
 import sxp
 
 class ArgError(StandardError):
@@ -50,39 +52,48 @@ class Args:
     def get_form_args(self, f, xargs=None):
         d = {}
         for (k, v) in f.items():
-            n = len(v)
             if ((k not in self.arg_dict) and
                 (k not in self.key_dict)):
                 continue
-            if n == 0:
-                continue
-            elif n == 1:
-                d[k] = v[0]
+            if isinstance(v, types.ListType):
+                n = len(v)
+                if n == 0:
+                    continue
+                elif n == 1:
+                    val = v[0]
+                else:
+                    raise ArgError('Too many values for %s' % k)
             else:
-                raise ArgError('Too many values for %s' % k)
+                val = v
+            d[k] = val
         return self.get_args(d, xargs=xargs)
 
     def coerce(self, type, v):
         try:
             if type == 'int':
-                return int(v)
-            if type == 'str':
-                return str(v)
-            if type == 'sxpr':
-                return self.sxpr(v)
+                val = int(v)
+            elif type == 'str':
+                val = str(v)
+            elif type == 'sxpr':
+                val = self.sxpr(v)
+            else:
+                raise ArgError('invalid type:' + str(type))
+            return val
         except ArgError:
             raise
         except StandardError, ex:
             raise ArgError(str(ex))
 
     def sxpr(self, v):
-        if instanceof(v, types.ListType):
-            return v
-        if instanceof(v, types.File) or hasattr(v, 'readline'):
-            return sxpr_file(v)
-        if instanceof(v, types.StringType):
-            return sxpr_file(StringIO(v))
-        return str(v)
+        if isinstance(v, types.ListType):
+            val = v
+        elif isinstance(v, types.FileType) or hasattr(v, 'readline'):
+            val = self.sxpr_file(v)
+        elif isinstance(v, types.StringType):
+            val = self.sxpr_file(StringIO.StringIO(v))
+        else:
+            val = str(v)
+        return val
 
     def sxpr_file(self, fin):
         try:
index 817d2818cef70a8bc88f055923ba3b0be56a1ced..3f9c41733479d1f6c0232143d38ac5c6b31d592b 100644 (file)
@@ -222,14 +222,19 @@ class Xend:
                          {'op'      : 'create',
                           'config'  : fileof(conf) })
 
-    def xend_domain(self, id):
-        return xend_get(self.domainurl(id))
+    def xend_domain_restore(self, filename):
+        return xend_call(self.domainurl(),
+                         {'op'      : 'restore',
+                          'file'    : filename })
 
     def xend_domain_configure(self, id, config):
         return xend_call(self.domainurl(id),
                          {'op'      : 'configure',
                           'config'  : fileof(conf) })
 
+    def xend_domain(self, id):
+        return xend_get(self.domainurl(id))
+
     def xend_domain_unpause(self, id):
         return xend_call(self.domainurl(id),
                          {'op'      : 'unpause'})
@@ -252,11 +257,6 @@ class Xend:
                          {'op'      : 'save',
                           'file'    : filename})
 
-    def xend_domain_restore(self, id, filename):
-        return xend_call(self.domainurl(id),
-                         {'op'      : 'restore',
-                          'file'    : filename })
-
     def xend_domain_migrate(self, id, dst):
         return xend_call(self.domainurl(id),
                          {'op'      : 'migrate',
index cb70cf41bc62672be6b30cb4087d95177a7796ba..80cda0d022c19be1ba4bf35fb067eddd9ad70c58 100644 (file)
@@ -19,9 +19,10 @@ class SrvDomain(SrvDir):
         self.xconsole = XendConsole.instance()
 
     def op_configure(self, op, req):
+        print 'op_configure>', op, req.args
         fn = FormFn(self.xd.domain_configure,
                     [['dom', 'int'],
-                     ['config', 'sxp']])
+                     ['config', 'sxpr']])
         val = fn(req.args, {'dom': self.dom.id})
         #todo: may need to add ok and err callbacks.
         return val